package com.example.supplierfinancin.controller;

import com.example.util.ContractTools;
import com.google.gson.JsonObject;
import org.fisco.bcos.sdk.abi.datatypes.generated.tuples.generated.Tuple2;
import org.fisco.bcos.sdk.abi.datatypes.generated.tuples.generated.Tuple5;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.swing.*;
import java.math.BigInteger;

@RestController
@RequestMapping("account")
public class AccountController {
    @PostMapping("show_company_details")
    public String show_company_details(String privatekey){
        /*
        return:
        {
            status:true
            data:{
                public_key:1515315...
                uscc:0000001
                type:1
                in_receipts:1561
                out_receipts:4463
            }
         }
         */

        Tuple5<String,String, BigInteger, BigInteger, BigInteger> temp= ContractTools.get_company_details(privatekey);

        JsonObject ret=new JsonObject();
        JsonObject data=new JsonObject();
        if(temp==null){
            ret.addProperty("status",false);
            ret.add("data",null);
        }else{
            data.addProperty("publickey",temp.getValue1());
            data.addProperty("uscc",temp.getValue2());
            data.addProperty("type",temp.getValue3());
            data.addProperty("in_receipts",temp.getValue4());
            data.addProperty("out_receipts",temp.getValue5());
            ret.addProperty("status",true);
            ret.add("data",data);
        }
        return ret.toString();
    }
}
